//
//  AppDelegate.m
//  UILabel1_4控件的其他属性和方法
//
//  Created by lanou3g on 15/12/21.
//  Copyright © 2015年 lanou3g. All rights reserved.
//

#import "AppDelegate.h"
#import "ViewController.h"
#define kRandomColor arc4random() % 255 /256.0
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    
    self.window.backgroundColor = [UIColor whiteColor];
    
    [self.window makeKeyAndVisible];
    
    ViewController *rootController = [[ViewController alloc]init];
    
    self.window.rootViewController = rootController;
    
#pragma mark ------ 练习UIView的其他属性和方法 ------
    
    UIView *aView = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
    
    aView.backgroundColor = [UIColor greenColor];
    
//    aView.hidden = YES;//是否隐藏
    
    aView.alpha = 0.8;//透明度
    
    [self.window addSubview:aView];
    
    UIView *bView = [[UIView alloc]initWithFrame:CGRectMake(100, 120, 100, 100)];
    
    bView.backgroundColor = [UIColor blackColor];
    
    [self.window addSubview:bView];
    
//    UIView *view = bView.superview;
//    NSLog(@"%@",[view class]);
    
//    [self.window insertSubview:bView atIndex:2];//插入子视图,在下标2
    
//    [self.window insertSubview:aView aboveSubview:bView];//插入子视图,在bView前
    
    [bView removeFromSuperview];
    [aView removeFromSuperview];
    
#pragma mark ------ 练习Label的其他属性和方法 ------
    
    for (int i = 0; i < 6;  i++) {
        
//        CGFloat labelX = 0;
        CGFloat labelY = 50;
        CGFloat labelW = 50;
        CGFloat labelH = 50;
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(i * labelW, labelY, labelW, labelH)];
        NSString *i1 = [NSString stringWithFormat:@"%d",i];
        label.text = i1;
        label.textAlignment = NSTextAlignmentCenter;
        
        label.backgroundColor = [UIColor colorWithRed:kRandomColor green:kRandomColor blue:kRandomColor alpha:kRandomColor];
//        switch (i) {
//            case 0:
//                label.backgroundColor = [UIColor greenColor];
//                break;
//            case 1:
//                label.backgroundColor = [UIColor cyanColor];
//                break;
//            case 2:
//                label.backgroundColor = [UIColor redColor];
//                break;
//            case 3:
//                label.backgroundColor = [UIColor blueColor];
//                break;
//            case 4:
//                label.backgroundColor = [UIColor purpleColor];
//                break;
//            case 5:
//                label.backgroundColor = [UIColor blackColor];
//                break;
//            default:
//                break;
//        }
        label.tag = 100 + i;
        
        
        [self.window addSubview:label];
        
        
    }
    
#pragma mark ------ 使用tag值更改View ------
    UIView *view = [self.window viewWithTag:100];
    view.frame = CGRectMake(100, 100, 100, 100);
    
    
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
